<template>
  <div class="right-menu">
    <div class="right-menu-box">
      <transition-group name="button-pop">
        <div
          class="right-menu-item"
          v-if="showButtons"
          key="phone"
          @click="handlePhoneClick"
        >
          <i class="iconfont icon-dianhua" style="font-size: 20px"></i>
        </div>
        <div
          class="right-menu-item"
          v-if="showButtons"
          key="top"
          @click="scrollToTop"
        >
          <i class="iconfont icon-huidaodingbu" style="font-size: 20px"></i>
        </div>
        <div
          class="right-menu-item"
          v-if="showButtons"
          key="qr"
          @click="handleQrClick"
        >
          <i class="iconfont icon-erweima" style="font-size: 20px"></i>
        </div>
      </transition-group>
      <div
        class="right-menu-item"
        @click="toggleButtons"
        :class="{ active: showButtons }"
      >
        <i
          class="iconfont"
          :class="showButtons ? 'icon-guanbi' : 'icon-caidan'"
          style="font-size: 20px"
        ></i>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";

const emit = defineEmits(["open-qr-dialog", "scrollToTop"]);

const showButtons = ref(true);

const toggleButtons = () => {
  showButtons.value = !showButtons.value;
};

// 回到顶部功能
const scrollToTop = () => {
  emit("scrollToTop");
  
};

// 处理电话点击
const handlePhoneClick = () => {
  window.location.href = "tel:400-123-4567"; // 替换为实际电话号码
};

// 处理二维码点击
const handleQrClick = () => {
  emit("open-qr-dialog"); // 触发父组件事件
};
</script>

<style scoped>
.right-menu {
  position: fixed;
  right: 2%;
  bottom: 10%;
  display: none;
}

.right-menu-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.right-menu-item {
  background: #fff;
  padding: 10px;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.right-menu-item:hover {
  background-color: #f5f5f5;
}

.button-pop-enter-active {
  transition: all 0.3s ease;
}

.button-pop-enter-from {
  opacity: 0;
  transform: translateY(100%);
}

.button-pop-leave-active {
  transition: none;
}

.right-menu-item.active {
  background-color: black;
}

.right-menu-item.active i {
  color: white;
  transform: rotate(180deg);
  transition: transform 0.3s ease;
}

.right-menu-item i {
  transition: transform 0.3s ease;
}
</style>
